package cn.kgc.tcst004.service.impl;

import cn.kgc.tcst004.dao.BlogMapper;
import cn.kgc.tcst004.pojo.Blog;
import cn.kgc.tcst004.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

@Service("BlogService")
public class BlogServiceImpl implements BlogService{

    @Autowired
    private BlogMapper blogMapper;

    public BlogMapper getBlogMapper() {
        return blogMapper;
    }

    public void setBlogMapper(BlogMapper blogMapper) {
        this.blogMapper = blogMapper;
    }
    @Override
    public List<Blog> getBlogs() {
        return blogMapper.getBlogs();
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public int insert(Blog blog) {
        int i = 0;
        try {
            i = blogMapper.insert(blog);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return i;
    }
}
